import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { name: 'welcome', path: '/welcome', component: () => import('@/views/welcome'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: true,
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index')
      }
    ]
  }
]
export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
// 异步路由
export const asyncRouterMap = [
  {
    path: '/system',
    component: Layout,
    meta: { title: '系统管理', icon: 'system' },
    children: [
      {
        path: 'role',
        name: 'system-role',
        component: () => import('@/views/system/role'),
        meta: { title: '权限组', icon: 'role',
          permissions: ['roles.index', 'roles.update', 'roles.destroy', 'roles.store'] }
      },
      {
        path: 'admin',
        name: 'system-admin',
        component: () => import('@/views/system/admin'),
        meta: { title: '管理员', icon: 'admin',
          permissions: ['school-admins.index', 'school-admins.update', 'school-admins.store', 'school-admins.refreshPassword'] }
      },
      {
        path: 'school',
        name: 'school-rule',
        component: () => import('@/views/system/school'),
        meta: {
          title: '学校设置', icon: 'school',
          permissions: ['school-rules.index', 'school-rules.update', 'schools.index', 'schools.update']
        }
      },
      {
        path: 'school-admin-log',
        name: 'school-admin-log',
        component: () => import('@/views/system/school-admin-log'),
        meta: {
          title: '操作日志', icon: 'log',
          permissions: ['school-admin-logs.index']
        }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    meta: { title: '用户管理', icon: 'user' },
    children: [
      {
        path: 'list',
        name: 'user-list',
        component: () => import('@/views/user/list'),
        meta: { title: '用户列表', icon: 'list',
          permissions: ['users.index', 'users.store', 'users.update', 'users.destroy', 'import-users.store'] }
      },
      {
        path: 'role',
        name: 'user-role',
        component: () => import('@/views/user/role'),
        meta: { title: '用户角色', icon: 'user_role',
          permissions: ['user-roles.index', 'user-roles.store', 'user-roles.update', 'user-roles.destroy'] }
      }
    ]
  },
  {
    path: '/food',
    component: Layout,
    meta: { title: '菜品管理', icon: 'food' },
    children: [
      {
        path: 'food-list',
        name: 'food-list',
        component: () => import('@/views/food/list'),
        meta: { title: '菜品列表', icon: 'list',
          permissions: ['foods.index', 'foods.store', 'foods.update'] }
      },
      {
        path: 'food-type',
        name: 'food-type',
        component: () => import('@/views/food/type'),
        meta: { title: '菜品种类', icon: 'type',
          permissions: ['food-types.index', 'food-types.store', 'food-types.update'] }
      }
    ]
  },
  {
    path: '/book-rule',
    component: Layout,
    meta: { title: '订餐规则', icon: 'book-rule' },
    children: [
      {
        path: 'book-rule',
        name: 'book-rule',
        component: () => import('@/views/book-rule/list'),
        meta: { title: '订餐规则', icon: 'list',
          permissions: ['book-rules.index', 'book-rules.store', 'book-rules.update', 'book-rules.settle', 'book-rules.destroy', 'price-categories.index',
            'book-rule-prices.store', 'book-rule-prices.update', 'book-rule-prices.destroy'] }
      },
      {
        path: 'price-categories',
        name: 'price-categories',
        component: () => import('@/views/book-rule/price-category'),
        meta: { title: '计费条目', icon: 'price',
          permissions: ['price-categories.index', 'price-categories.store', 'price-categories.update'] }
      }
    ]
  },
  {
    path: '/book-order',
    component: Layout,
    meta: { title: '订单管理', icon: 'book-order' },
    children: [
      {
        path: 'book-order',
        name: 'book-order',
        component: () => import('@/views/book-order/list'),
        meta: { title: '订单列表', icon: 'list', permissions: ['book-orders.index', 'book-orders.update'] }
      },
      {
        path: 'book-statistics',
        name: 'book-statistics',
        component: () => import('@/views/book-order/statistics'),
        meta: { title: '订单统计', icon: 'order-statistics', permissions: ['order-statistics.index'] }
      },
      {
        path: 'order-reviews',
        name: 'order-reviews',
        component: () => import('@/views/book-order/review'),
        meta: { title: '公务订单', icon: 'order-review', permissions: ['order-reviews.index', 'order-reviews.update'] }
      },
      {
        path: 'meal-statistics',
        name: 'meal-statistics',
        component: () => import('@/views/book-order/meal-statistics'),
        meta: { title: '用餐统计', icon: 'meal', permissions: ['meal-statistics.index'] }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

